package com.yxj01;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

class Student {
    String name;
    int age;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }
}

public class TestStu {
    public static void main(String[] args) {
        //创建List集合对象
        List<Student> list = new ArrayList<Student>();
        //创建学生对象
        Student s1 = new Student("yxj",23);
        Student s2 = new Student("ymm",23);
        Student s3 = new Student("yxx",34);

        list.add(s1);
        list.add(s2);
        list.add(s3);

        //1.迭代器方法
        Iterator<Student> it = list.iterator();
        while(it.hasNext()) {
            Student s = it.next();
            System.out.println(s.getName()+","+s.getAge());
        }
        System.out.println("===========");
        //FOR循环
        for(int i = 0; i < list.size(); i++) {
            Student s = list.get(i);
            System.out.println(s.getName()+","+s.getAge());
        }

    }
}
